package com.kingwood.algorithm.test;

import java.util.*;

/**
 * API集群负载统计
 * https://fcqian.blog.csdn.net/article/details/134635782
 */
public class LoadbalanceCouont {

    public static int getAppearTimes(List<String> list, int level, String word) {
        HashMap<String, Integer>[] countMapArray = new HashMap[10];

        for (String item : list) {
            String[] strArray = item.split("/");
            int len = strArray.length;
            for (int i=1; i<len; i++) {
                HashMap<String, Integer> countMap = countMapArray[i - 1] == null ? new HashMap<>() : countMapArray [i - 1];
                String apiWord = strArray[i];
                int times = countMap.getOrDefault(apiWord, 0) + 1;
                countMap.put(apiWord, times);
                countMapArray[i-1] = countMap;
            }
        }

        HashMap<String, Integer> countMap = countMapArray[level - 1];
        if (countMap == null) {
            return 0;
        }

        return countMap.getOrDefault(word, 0);
    }

    public static void main(String[] args) {
        String str = "/abc/efg/hij/ddd";
        String[] strArray = str.split("/");
        System.out.println(Arrays.toString(strArray));

        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        List<String> list = new ArrayList<>();

        for (int i=0; i<n; i++) {
            String item = scanner.next();
            list.add(item);
        }

        int level = scanner.nextInt();
        String word = scanner.next();
        System.out.println(getAppearTimes(list, level, word));
    }
}
